package top.z.work.module.system.convert;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import top.z.work.framework.common.pojo.PageInfo;
import top.z.work.module.system.controller.route.vo.SystemRouteCreateVO;
import top.z.work.module.system.controller.route.vo.SystemRouteModifyVO;
import top.z.work.module.system.controller.route.vo.SystemRouteVO;
import top.z.work.module.system.entity.SystemRoute;

import java.util.List;

@Mapper
public interface SystemRouteConvert {

    SystemRouteConvert INSTANCE = Mappers.getMapper(SystemRouteConvert.class);

    default QueryWrapper convert(SystemRouteVO data) {
        return QueryChain.of(SystemRoute.class)
                .eq(SystemRoute::getIdentity, data.getIdentity())
                .eq(SystemRoute::getParent, data.getParent())
                .eq(SystemRoute::getName, data.getName())
                .eq(SystemRoute::getIcon, data.getIcon())
                .eq(SystemRoute::getAuthority, data.getAuthority())
                .eq(SystemRoute::getPath, data.getPath())
                .eq(SystemRoute::getComponent, data.getComponent())
                .eq(SystemRoute::getType, data.getType())
                .eq(SystemRoute::getSort, data.getSort())
                .eq(SystemRoute::getStatus, data.getStatus())
                .eq(SystemRoute::getVisible, data.getVisible())
                ;
    }

    SystemRouteVO convert(SystemRoute data);

    SystemRoute convert(SystemRouteCreateVO data);

    SystemRoute convert(SystemRouteModifyVO data);

    List<SystemRouteVO> convert(List<SystemRoute> list);

    default PageInfo<SystemRouteVO> convert(Page<SystemRoute> page) {
        List<SystemRouteVO>     list     = page.getRecords().stream().map(this::convert).toList();
        PageInfo<SystemRouteVO> pageInfo = new PageInfo<>();
        pageInfo.setList(list);
        pageInfo.setTotal(page.getTotalRow());
        pageInfo.setSize(page.getPageSize());
        pageInfo.setPage(page.getPageNumber());
        return pageInfo;
    }

}
